package kr.hkit.powerjava.algorithm;

import java.util.Arrays;

public class Stack implements Structure {
	private int size ; //스택의 크기
	private int top;
	private String[] arrItem;
	
	public Stack(int size) {
		this.size = size;
		arrItem = new String [size];
		top = -1;
	}
	
	public void push(String item) {
		
		if (!isFull()){ //full이 아니라면
			arrItem[++top] = item;
		}else{
			System.out.println("Stack is Full");
		}
	}
	
	public String pop(){
		
		if(!isEmpty()) { //empty가 아니면
			return arrItem[top--];
		}else{
			return "Stack is Empty" ;
		}
	}
	
	public boolean isFull(){ //full일 경우
		return top==size-1; // !!!!!
	}
	
	public boolean isEmpty() { //empty일 경우
		return top==-1;
	}
	
	public void prn() { 
		for (int i = 0; i <= top; i++) {
			System.out.printf("[%s]\t", arrItem[i]);
		}
		System.out.println();
	}

	@Override
	public String toString() {
		return String.format("%s%n", Arrays.toString(arrItem));
	}
}
